package com.scott.ch010;

/**
 * @author 黄后林
 * @version 1.0
 * @note 定义测试类StudentTest、在测试类Student中定义测试方法Comparable getMax(Comparable c1,Comparable c2)完成测试
 * @date 2022-05-02 10:26:06
 */
public class StudentTest {


    public static void main(String[] args) {

        Student scott = new Student();
        scott.setStudentName("scott");
        scott.setAge(39);

        Student peng = new Student();
        peng.setStudentName("peng");
        peng.setAge(36);

        Comparable max = getMax(scott, peng);
        System.out.println(max);

        System.out.println(getMax(peng, scott));


    }


    public static  Comparable getMax(Comparable c1,Comparable c2){

        // 如果result>0  则c1比c2大
        // 如果result<0  则c1比c2小
        // 如果result==0 则c1和c2相等

        int result = c1.compareTo(c2);

        if(result>=0){
            return c1;
        }else{
            return c2;
        }
    }
}
